/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sn.metier;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author chenry08
 */
@Entity
public class Partage implements Serializable, Comparable<Partage> {
	//attributs
        @Id
        @GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;
        
        
        @Column
	private String message;
        
        @ManyToOne(fetch= FetchType.EAGER)
	private Personne auteur;
        
        @ManyToMany
	private List<Personne> destinataire;
        
        @Temporal(TemporalType.TIMESTAMP)
        private Date datePartagee= new Date();
	
	//méthodes
	public String getPartage(){
		return "plouf_Partage";
	}
	
	//constructeurs
	public Partage() {}

	public Partage(Long id) {
		this.id = id;
	}

	public Partage(String message, Personne auteur, List<Personne> destinataire) {
		this.message = message;
		this.auteur = auteur;
		this.destinataire = destinataire;
	}
        
	
	//get & set
	public Personne getAuteur() {
		return auteur;
	}

	public void setAuteur(Personne auteur) {
		this.auteur = auteur;
	}

	public List<Personne> getDestinataire() {
		return destinataire;
	}

	public void setDestinataire(List<Personne> destinataire) {
		this.destinataire = destinataire;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

        public Date getDatePartagee() {
            return datePartagee;
        }

        public void setDatePartagee(Date datePartagee) {
            this.datePartagee = datePartagee;
        }

        
	//comparateurs
	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final Partage other = (Partage) obj;
		if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public int hashCode() {
		int hash = 3;
		hash = 67 * hash + (this.id != null ? this.id.hashCode() : 0);
		return hash;
	}

    @Override
    public int compareTo(Partage o) {
        return -1*this.getDatePartagee().compareTo(o.getDatePartagee());
    }
	
}
